package model

import (
	"gorm.io/gorm"
	"love-link/love-server/basic/config"
)

type VipCharge struct {
	gorm.Model
	UserID  int     `gorm:"type:int(11);comment:用户"`
	OrderID int     `gorm:"type:int(11);comment:订单"`
	Status  string  `gorm:"type:varchar(30);comment:会员等级"`
	Price   float64 `gorm:"type:decimal(10,2);comment:金额"`
	Type    string  `gorm:"type:varchar(30);comment:支付方式"`
}

func CreateVip(v *VipCharge) error {

	return config.DB.Create(&v).Error
}

type VipType struct {
	gorm.Model
	Name    string  `gorm:"type:varchar(30);comment:会员名称"`
	Price   float64 `gorm:"type:decimal(10,2);comment:会员价格"`
	VipTime string  `gorm:"type:varchar(30);comment:会员时长"`
}

func FindVip(v *VipType) error {

	return config.DB.First(&v).Error
}

type Order struct {
	gorm.Model
	UserId  int     `gorm:"type:int(11);comment:用户ID"`
	VipId   int     `gorm:"type:int(11);comment:套餐ID"`
	OrderId string  `gorm:"varchar(18);comment:订单编号"`
	Price   float64 `gorm:"type:decimal(10,2);comment:金额"`
}

func CreateOrder(o *Order) error {

	return config.DB.Create(&o).Error
}

type User struct {
	gorm.Model
	Username string `gorm:"type:varchar(30);comment:用户名"`
	Vip      string `gorm:"type:varchar(30);comment:会员等级"`
	VipTime  string `gorm:"type:varchar(30);comment:过期时间"`
}

func Update(u *User, id int64) error {
	return config.DB.Where("id=?", id).Updates(&u).Error
}
